package com.kuyun.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.kuyun.entity.User;
import com.kuyun.service.UserService;
import com.kuyun.tools.Constants;

@Controller
@RequestMapping(value = "/")
public class UserController {

	@Resource
	private UserService userService;
	
	
	// 主页
	@RequestMapping(value = "/index")
	public String show(HttpSession session, Model model) {
		// 免登录处理->给予正确的一个账户和密码
		String userName = "夜雨倾城";
		String password = "123456";
		// 查询用户是否存在
		User user = userService.findUser(userName, password);
		// 验证用户是否存在
		if (user != null) {
			// 验证用户是否为数据库管理员
			if (user.getJurisdiction() == 1) {
				user.setId(user.getId());
				user.setUserName(user.getUserName());
				user.setPicPath(user.getPicPath());
				user.setPassword("");
				session.setAttribute(Constants.USER_SESSION, user);
				model.addAttribute("user", user);
			} else {
				return "404";
			}
		} else {
			return "404";
		}
		return "index";
	}

	// 我的主页
	@RequestMapping(value = "/showUser")
	public String showUser() {
		return "index";
	}

}
